package com.yy.controller;

import com.yy.opengaussdriver.OpenGaussJDBC;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;

/**
 * @author 鱼凫
 * @version 1.0
 * Create by 2022/4/8 18:04
 * @Description OpenGauss连接测试
 */

@RestController
@RequestMapping("/getMes")
public class ConnectTest {
    @RequestMapping("/sendTest")
    public HashMap<Integer ,String> sendTest() throws SQLException{
        Connection connection  = OpenGaussJDBC.getConnect("ren","abcd@123");
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from proj.ren.role;");
        HashMap<Integer,String> map = new HashMap<>();
        while (resultSet.next()){
            Object roleId = resultSet.getObject("roleid");
            Object roleName = resultSet.getObject("rolename");
            Object roleDescribe = resultSet.getObject("roledescribe");
            map.put((Integer) roleId,(String) roleName);
            System.out.println("角色ID:" + roleId.toString() + "角色名" + roleName.toString() + "角色描述" + roleDescribe.toString());
        }
        resultSet.close();
        return map;
    }
}
